<template>
  <div class="in-wrap">
    <!-- 公共头引入 -->
    <header id="header">
      <section class="container">
        <h1 id="logo">
          <a href="#" title="厚溥云课堂">
            <img src="~/assets/img/logo.png" width="100%" alt="厚溥云课堂">
          </a>
        </h1>
        <div class="h-r-nsl">
          <ul class="nav">
            <router-link to="/" tag="li" active-class="current"  exact>
              <a>首页</a>
            </router-link>
            <router-link to="/course" tag="li" active-class="current">
              <a>课程</a>
            </router-link>
            <router-link to="/teacher" tag="li" active-class="current">
              <a>名师</a>
            </router-link>
            <router-link to="/article" tag="li" active-class="current">
              <a>文章</a>
            </router-link>
            <router-link to="/qa" tag="li" active-class="current">
              <a>问答</a>
            </router-link>
          </ul>
          <!-- / nav -->
          <ul class="h-r-login">
            <li id="no-login" v-if="!user">
              <a href="/login" title="登录">
                <em class="icon18 login-icon">&nbsp;</em>
                <span class="vam ml5">登录</span>
              </a>
              |
              <a href="/register" title="注册">
                <span class="vam ml5">注册</span>
              </a>
            </li>
            <li v-if="user" class="mr10" id="is-login-one">
              <a href="#" title="消息" id="headerMsgCountId">
                <em class="icon18 news-icon">&nbsp;</em>
              </a>
              <q class="red-point" style="display: none">&nbsp;</q>
            </li>
            <li v-if="user" class="h-r-user" id="is-login-two">
              <a href="/order/list" title> 
                <span class="vam" id="userName">欢迎您:{{user.nickName}}</span>
              </a>|
              <a href="javascript:void(0)" title="退出" @click="logout" class="ml5">退出</a>
            </li>
            <!-- /未登录显示第1 li；登录后显示第2，3 li -->
          </ul>
          <aside class="h-r-search">
            <form action="#" method="post">
              <label class="h-r-s-box">
                <input type="text" placeholder="输入你想学的课程" @keyup.enter="search"  v-model="courseTitle">
                <button type="submit" class="s-btn" @click.prevent="search">
                  <em class="icon18">&nbsp;</em>
                </button>
              </label>
            </form>
          </aside>
        </div>
        <aside class="mw-nav-btn">
          <div class="mw-nav-icon"></div>
        </aside>
        <div class="clear"></div>
      </section>
    </header>
      
    <!-- /公共头引入 -->
    <nuxt/>

    <!-- 公共底引入 -->
    <footer id="footer">
      <section class="container">
        <div class>
          <h4 class="hLh30">
            <span class="fsize18 f-fM c-999">友情链接</span>
          </h4>
          <ul class="of flink-list">
            <li>
              <a href="https://www.bailiban.com/" title="百里半" target="_blank">百里半</a>
            </li>
          </ul>
          <div class="clear"/>
        </div>
        <div class="b-foot">
          <section class="fl col-7">
            <section class="mr20">
              <section class="b-f-link">
                <a href="#" title="关于我们" target="_blank">关于我们</a>|
                <a href="#" title="联系我们" target="_blank">联系我们</a>|
                <a href="#" title="帮助中心" target="_blank">帮助中心</a>|
                <a href="#" title="资源下载" target="_blank">资源下载</a>|
                <span>服务热线：0371-88888888(郑州) </span>
               
              </section>
              <section class="b-f-link mt10">
                <span>©2021 课程版权均归厚溥云课堂所有 </span>
              </section>
            </section>
          </section>
          <aside class="fl col-3 tac mt15">
            <section class="gf-tx">
              <span>
                <img src="~/assets/img/wx-icon.png" >
              </span>
            </section>
            <section class="gf-tx">
              <span>
                <img src="~/assets/img/wb-icon.png" >
              </span>
            </section>
          </aside>
          <div class="clear"/>
        </div>
      </section>
    </footer>
    <!-- /公共底引入 -->
  </div>
</template>
<script>
  import '~/assets/css/reset.css'
  import '~/assets/css/theme.css'
  import '~/assets/css/global.css'
  import '~/assets/css/web.css'
  import '~/assets/css/base.css'
  import '~/assets/css/activity_tab.css'
  import '~/assets/css/bottom_rec.css'
  import '~/assets/css/nice_select.css'
  import '~/assets/css/order.css'
  import '~/assets/css/swiper-3.3.1.min.css'
  import "~/assets/css/pages-weixinpay.css"
  import cookie from 'js-cookie'
  export default {
  data(){
    return{
      courseTitle:cookie.get('keyword'),
      user:null,//当前登录用户信息
    }
  },
  mounted(){
    //判断当前用户是否登录，如果登陆，获取用户信息
    if (cookie.get('member_token')) {
      //获取用户信息
      //console.log(cookie.get('member_info'));
      this.user=JSON.parse(cookie.get('member_info')) 
    }
  },
  methods:{
    search(){
      //console.log(this.courseTitle);
      //将搜索关键词存入cookie中
        cookie.set('keyword',this.courseTitle)
        //记录当前搜索状态
        cookie.set('search',true)
      //跳转至课程列表页面
      location.href='/course'
    },
    //退出
    logout(){
      this.$confirm('您确定要退出吗?', '系统提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           //清除cookie中的token和用户信息
            cookie.remove('member_token')
            cookie.remove('member_info')
            //跳转至首页
            location.href='/'
        }).catch(() => {       
      });
    }
  }
};
</script>